import { observable, action } from 'mobx';
import { WeaTableNew, WeaForm, WeaLogView } from 'comsMobx';
import * as Api from './../apis/alterLogApi';

const { LogStore } = WeaLogView;
const { TableStore } = WeaTableNew;

class AlterLogStore {
  @observable topTab = [];
  @observable selectedKey = '0';
  @observable logTableStore = new TableStore();
  @observable logStore = new LogStore();
  @observable groupid = '';// 每一行的操作
  @observable SearchForm = new WeaForm();
  @observable showSearchDrop = false;// 高级搜索显隐
  @observable showSearchAd = false;// 高级搜索form显隐
  @observable targetId = '';// 每一行对应的id
  @observable logVisible = false; // 日志弹窗的显隐
  @observable logType = '';
  @observable logSmallType = '';
  // 切换页签
  @action.bound changeDate(v) {
    this.selectedKey = v;
    for (let list of this.topTab) {
      if (list.viewcondition == v) {
        this.groupid = list.groupid;
      }
    }
    this.getLogTableData();
  }
  // 获取顶部页签数据
  @action.bound getTabData() {
    Api.getTabData().then((data) => {
      this.topTab = data.topTab;
    });
  }
  // 获取table数据
  @action.bound getSearchData() {
    const formData = this.SearchForm.getFormParams();
    const params = {
      groupid: formData.groupid || '',
      operator: formData.operator || '',
      startDate: formData.startDate || '',
      endDate: formData.endDate || '',
    };
    Api.getLogTableData(params).then((data) => {
      if (data.sessionkey) {
        this.logTableStore.getDatas(data.sessionkey, 1, 10);
        this.showSearchAd = false;
        this.selectedKey = '0';
      }
    });
  }

  // 获取初始table
  @action.bound getLogTableData() {
    const params = { groupid: this.groupid };
    Api.getLogTableData(params).then((data) => {
      if (data.sessionkey) {
        this.logTableStore.getDatas(data.sessionkey, 1, 10);
      }
    });
  }

  // 获取高级条件form
  @action.bound getSearchForm() {
    Api.getSearchForm().then((data) => {
      this.SearchForm.setCondition(data.items);
    });
  }
  // 关闭日志弹窗
  @action.bound toggleLog() {
    this.logVisible = false;
    this.targetId = '';
  }
  // 查看
  @action.bound lookOver(targetId, logSmallType) {
    this.targetId = targetId;
    this.logSmallType = logSmallType;
    this.logVisible = true;
  }
  // 点击高级搜索
  @action.bound showtTag() {
    this.showSearchAd = !this.showSearchAd;
  }
  // 获取日志的参数
  @action.bound getLogParams() {
    Api.getLogParams().then((data) => {
      this.logType = data.logType;
    });
  }
}
const alterLogStore = new AlterLogStore();
export default alterLogStore;
